package com.example.demo.controller;

import com.example.demo.entity.dto.ResultBean;
import com.example.demo.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: chenyu
 * @date: 2020/8/5 16:18
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService service;

    //上传文件，返回文件
    @RequestMapping(method = RequestMethod.POST)
    public ResultBean<String> uploadFile(@RequestParam("file") MultipartFile file) {
        return new ResultBean<>(service.insert(file));
    }

    //删除文件
    @RequestMapping(method = RequestMethod.GET)
    public ResultBean<Boolean> deleteFile(@RequestParam("fileName")  String fileName) {
        return new ResultBean<>(service.delete(fileName));
    }

    @PostMapping("/uploadUserPhoto")
    public ResultBean<String> uploadUserPhoto(@RequestParam("photo") MultipartFile file){
        return new ResultBean<>(service.insertUserPhoto(file));
    }

}
